<?
session_start();
include 'php/connect.php';

$specId = mysql_real_escape_string($_POST['spec']);
$layout = mysql_real_escape_string($_POST['layout']);

if($specId != "" && $specId != undefined){
	$abfrage = "SELECT spec.layout, spec.userId, user.userName, spec.description, spec.public
	FROM ((SELECT * FROM ffxivc_specs WHERE specId = \"".$specId."\") spec
		LEFT JOIN
		ffxivc_users user
		ON spec.userId = user.userId)
		";
			
	$res = mysql_query($abfrage);	
	$num = mysql_num_rows($res);	
	if ($res && $num == 1){
	
		$temp_pub = mysql_result($res, 0, "public");
		$temp_uid = mysql_result($res, 0, "userId");
		
		if($temp_pub == "Y" || $temp_uid == $_SESSION['userId']){
			$layout = mysql_result($res, 0, "layout");
			$specUserId = mysql_result($res, 0, "userId");
			$desc = mysql_result($res, 0, "description");
			$userName = mysql_result($res, 0, "userName");
		}else{
			$specId = -1;
		}
	}else{
		$specId = -1;
	}
}else{
	$specId = -1;
}
$sowner = 0;
$userId = -1;
if(isset($_SESSION['userId'])){
	$userId = mysql_real_escape_string($_SESSION['userId']);
	if($specUserId==$userId){
		$sowner = 1;
	}
}


?>
<html>
	<head>
	<!-- Calculator -->
	</head>
	<body>
		<script>		
					$(document).ready(function(){
						$('.show-user').click(function(e) {	
							var clicked = jQuery(e.target);
							var id = clicked.attr('id');
							getUser(id);
						});
					});
		</script>
		<div class = 'content-title-container'>
<?		if(isset($userName) && $userName != ""){
			echo "<div id='".$userName."' class='show-user cur-point normal-text blue-text content-title-text fl-left' >".$userName."</div><div class='normal-text grey-text content-title-text fl-left' style='margin-left: 5px;'>'s Spec</div>";
		}else{
			echo "<div class='normal-text grey-text content-title-text'>Create a Spec</div>";
		}
			
?>
		</div>
		<div id='indent-content-container' class='me-content-container'>
			<div class = 'content-subtitle-container-open'></div>
			<div style="padding-left: 25px;">
				<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" 
					codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,16,0"
					width="735" height="720" >
					<param name="movie" value="swf/ffxivcalc.swf?layout=<? echo(urlencode($layout)) ?>&userId=<? echo(urlencode($userId)) ?>&specId=<? echo(urlencode($specId)) ?>&sowner=<? echo($sowner) ?>&desc=<? echo(urlencode($desc)) ?>&version=1.2">
					<param name="quality" value="high">
					<param name="play" value="true">
					<param name="LOOP" value="false">
					<param name="bgcolor" value="#222222">
					<embed src="swf/ffxivcalc.swf?layout=<? echo(urlencode($layout)) ?>&userId=<? echo(urlencode($userId)) ?>&specId=<? echo(urlencode($specId)) ?>&sowner=<? echo($sowner) ?>&desc=<? echo(urlencode($desc)) ?>&version=1.2" bgcolor="#222222" width="735" height="720" play="true" loop="false" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" 
					type="application/x-shockwave-flash">
					</embed>
				</object>
			</div>
			<div class = 'content-subtitle-container-close'></div>
		</div>
	</body>
</html>